summaryrefslogtreecommitdiff
path: root/app/[lng]/partners/(partners)/vendor-data/layout.tsx
blob: c37a983a99adf3cf854d523fce4b98d654f7e135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// app/vendor-data/layout.tsx
import * as React from "react"
import { cookies } from "next/headers"
import { Shell } from "@/components/shell"
import { getVendorProjectsAndContracts } from "@/lib/vendor-data/services"
import { VendorDataContainer } from "@/components/vendor-data/vendor-data-container"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import { getServerSession } from "next-auth"
import { InformationButton } from "@/components/information/information-button"
import { useTranslation } from "@/i18n"

interface VendorDataLayoutProps {
  children: React.ReactNode
  params: { lng?: string }
}

// Layout 컴포넌트는 서버 컴포넌트입니다
export default async function VendorDataLayout({
  children,
  params,
}: VendorDataLayoutProps) {
  // 기본 언어는 'ko'로 설정, params.locale이 있으면 사용
  const { lng } = await params;
  const language = lng || 'en'
  const { t } = await useTranslation(language, 'engineering')

  const session = await getServerSession(authOptions)
  const vendorId = session?.user.companyId
  // const vendorId = "17"
  const idAsNumber = Number(vendorId)
   
  // 프로젝트 데이터 가져오기
  const projects = await getVendorProjectsAndContracts(idAsNumber) 

  // 레이아웃 설정 쿠키 가져오기
  // Next.js 15에서는 cookies()가 Promise를 반환하므로 await 사용
  const cookieStore = await cookies()
   
  // 이제 cookieStore.get() 메서드 사용 가능
  const layout = cookieStore.get("react-resizable-panels:layout:mail")
  const collapsed = cookieStore.get("react-resizable-panels:collapsed")
   
  const defaultLayout = layout ? JSON.parse(layout.value) : undefined
  const defaultCollapsed = collapsed ? JSON.parse(collapsed.value) : undefined 

  return (
    <Shell className="gap-2">
      <div className="flex items-center justify-between space-y-2">
        <div className="flex items-center justify-between space-y-2">
          <div>
            <div className="flex items-center gap-2">
              <h2 className="text-2xl font-bold tracking-tight">
                {t('layout.page_title')}
              </h2>
              <InformationButton pagePath="partners/vendor-data" />
            </div>
            {/* <p className="text-muted-foreground">
              각종 Data 입력할 수 있습니다
            </p> */}
          </div>
        </div>
      </div>
      
      <section className="overflow-hidden rounded-[0.5rem] border bg-background shadow">
        <div className="hidden flex-col md:flex">
          {projects.length === 0 ? (
            <div className="p-4 text-center text-sm text-muted-foreground">
              {t('layout.no_projects')}
            </div>
          ) : (
            <VendorDataContainer
              projects={projects}
              defaultLayout={defaultLayout}
              defaultCollapsed={defaultCollapsed}
              navCollapsedSize={4}
            >
              {/* 페이지별 콘텐츠가 여기에 들어갑니다 */}
              {children}
            </VendorDataContainer>
          )}
        </div>
      </section>
    </Shell>
  )
}